
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Lab 3: Respond to ARP · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-flexible-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-page-toc-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-auto-scroll-table/website.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../../styles/website.css">
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="preparation.html" />
    
    
    <link rel="prev" href="../ipv4-router.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../../">
            
                <a href="../../../">
            
                    
                    Computer Network Lab Manual
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../ch01/lab-1.html">
            
                <a href="../../ch01/lab-1.html">
            
                    
                    Lab 1: Switchyard & Mininet
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../../ch01/prerequisites.html">
            
                <a href="../../ch01/prerequisites.html">
            
                    
                    Task 1: Prerequisites
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.1" data-path="../../ch01/linux.html">
            
                <a href="../../ch01/linux.html">
            
                    
                    Linux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.2" data-path="../../ch01/python.html">
            
                <a href="../../ch01/python.html">
            
                    
                    Python
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.3" data-path="../../ch01/git.html">
            
                <a href="../../ch01/git.html">
            
                    
                    Git
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../../ch01/workflow.html">
            
                <a href="../../ch01/workflow.html">
            
                    
                    Task 2: Workflow
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.2.1" data-path="../../ch01/vscode.html">
            
                <a href="../../ch01/vscode.html">
            
                    
                    VS Code
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.2" data-path="../../ch01/mininet.html">
            
                <a href="../../ch01/mininet.html">
            
                    
                    Mininet
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.3" data-path="../../ch01/wireshark.html">
            
                <a href="../../ch01/wireshark.html">
            
                    
                    Wireshark
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.4" data-path="../../ch01/switchyard.html">
            
                <a href="../../ch01/switchyard.html">
            
                    
                    Switchyard
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../../ch01/nju-gitlab.html">
            
                <a href="../../ch01/nju-gitlab.html">
            
                    
                    Task 3: NJU GitLab
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../../ch01/modification.html">
            
                <a href="../../ch01/modification.html">
            
                    
                    Task 4: Modification
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../../ch02/lab-2.html">
            
                <a href="../../ch02/lab-2.html">
            
                    
                    Lab 2: Learning Switch
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../../ch02/preparation.html">
            
                <a href="../../ch02/preparation.html">
            
                    
                    Task 1: Preparation
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../../ch02/basic-switch.html">
            
                <a href="../../ch02/basic-switch.html">
            
                    
                    Task 2: Basic Switch
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../../ch02/timeouts.html">
            
                <a href="../../ch02/timeouts.html">
            
                    
                    Task 3: Timeouts
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../../ch02/lru.html">
            
                <a href="../../ch02/lru.html">
            
                    
                    Task 4: Least Recently Used
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../../ch02/ltv.html">
            
                <a href="../../ch02/ltv.html">
            
                    
                    Task 5: Least Traffic Volume
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../../ch02/faq.html">
            
                <a href="../../ch02/faq.html">
            
                    
                    FAQ
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../ipv4-router.html">
            
                <a href="../ipv4-router.html">
            
                    
                    Lab 3-5: IPv4 Router
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.4.1" data-path="lab-3.html">
            
                <a href="lab-3.html">
            
                    
                    Lab 3: Respond to ARP
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1.1" data-path="preparation.html">
            
                <a href="preparation.html">
            
                    
                    Task 1: Preparation
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.1.2" data-path="handle-arp-request.html">
            
                <a href="handle-arp-request.html">
            
                    
                    Task 2: Handle ARP Request
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.1.3" data-path="arp-table.html">
            
                <a href="arp-table.html">
            
                    
                    Task 3: Cached ARP Table
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../faq.html">
            
                <a href="../faq.html">
            
                    
                    FAQ
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../../../appendix/appendix.html">
            
                <a href="../../../appendix/appendix.html">
            
                    
                    Appendix
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../../../appendix/environment-setup.html">
            
                <a href="../../../appendix/environment-setup.html">
            
                    
                    Environment Setup
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../../../appendix/about-this-repository.html">
            
                <a href="../../../appendix/about-this-repository.html">
            
                    
                    About This Repository
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../.." >Lab 3: Respond to ARP</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="lab-3-respond-to-arp"><a name="lab-3-respond-to-arp" class="plugin-anchor" href="#lab-3-respond-to-arp"><i class="fa fa-link" aria-hidden="true"></i></a>Lab 3: Respond to ARP</h1>
<h2 id="overview"><a name="overview" class="plugin-anchor" href="#overview"><i class="fa fa-link" aria-hidden="true"></i></a>Overview</h2>
<p>This is the first in a series of exercises that have the ultimate goal of creating an IPv4 router. The basic functions of an Internet router are to:</p>
<ol>
<li>Respond to ARP (Address Resolution Protocol) requests for addresses that are assigned to interfaces on the router.</li>
<li>Make ARP requests for IP addresses that have no known Ethernet MAC address. A router will often have to send packets to other hosts, and needs Ethernet MAC addresses to do so.</li>
<li>Receive and forward packets that arrive on links and are destined to other hosts. Part of the forwarding process is to perform address lookups (&quot;longest prefix match&quot; lookups) in the forwarding information base. You will eventually just use &quot;static&quot; routing in your router, rather than implement a dynamic routing protocol like RIP or OSPF.</li>
<li>Respond to Internet Control Message Protocol (ICMP) messages like echo requests (&quot;pings&quot;).</li>
<li>Generate ICMP error messages when necessary, such as when an IP packet&apos;s TTL (time to live) value has been decremented to zero.</li>
</ol>
<p>The goal of this first stage of building the router is to accomplish item <strong>#1</strong> above: respond to ARP requests.</p>
<h2 id="your-tasks"><a name="your-tasks" class="plugin-anchor" href="#your-tasks"><i class="fa fa-link" aria-hidden="true"></i></a>Your Tasks</h2>
<p>In the source directory for this exercise, there is a Python file to use as a starter template: <code>myrouter.py</code>. This file contains the outline of a Router class, and currently contains a constructor (<code>__init__</code>) method and a <code>router_main</code> method. This is just a starter template: you can refactor and redesign the code in any way you like.</p>
<p>The main task for this exercise is to modify the Router class to do the following:</p>
<blockquote>
<p>[!NOTE]
The sentences marked with &#x2705; are related to the content of your report. Please pay attention.</p>
</blockquote>
<h3 id="task-1-preparation"><a name="task-1-preparation" class="plugin-anchor" href="#task-1-preparation"><i class="fa fa-link" aria-hidden="true"></i></a>Task 1: Preparation</h3>
<p>Initiate your project with our template.</p>
<p><a href="preparation.html">Start the task here</a></p>
<h3 id="task-2-handle-arp-requests"><a name="task-2-handle-arp-requests" class="plugin-anchor" href="#task-2-handle-arp-requests"><i class="fa fa-link" aria-hidden="true"></i></a>Task 2: Handle ARP Requests</h3>
<p>Ready to make ARP work.</p>
<p><a href="handle-arp-request.html">Start the task here</a></p>
<h3 id="task-3-cached-arp-table"><a name="task-3-cached-arp-table" class="plugin-anchor" href="#task-3-cached-arp-table"><i class="fa fa-link" aria-hidden="true"></i></a>Task 3: Cached ARP Table</h3>
<p>Maintain a correlation between each MAC address and its corresponding IP address.</p>
<p><a href="arp-table.html">Start the task here</a></p>
<h2 id="handing-it-in"><a name="handing-it-in" class="plugin-anchor" href="#handing-it-in"><i class="fa fa-link" aria-hidden="true"></i></a>Handing it in</h2>
<h3 id="report"><a name="report" class="plugin-anchor" href="#report"><i class="fa fa-link" aria-hidden="true"></i></a>Report</h3>
<p>We will provide a template of your lab assignment report <a href="https://box.nju.edu.cn/d/123a70ac8ff34595b18f/" target="_blank">here</a>. You need to submit the report in your repository named <code>&lt;&#x5B66;&#x53F7;&gt;&lt;&#x59D3;&#x540D;&gt;_lab_3</code>. The format of your report can be Microsoft Doc or PDF. An example is <code>123456789&#x62FE;&#x4F70;&#x4EDF;_lab_3.docx</code>.</p>
<h3 id="submit-to-nju-gitlab"><a name="submit-to-nju-gitlab" class="plugin-anchor" href="#submit-to-nju-gitlab"><i class="fa fa-link" aria-hidden="true"></i></a>Submit to NJU GitLab</h3>
<p>To submit your work, you need to do the following things.</p>
<ol>
<li><p>Modify your code and complete your report.</p>
</li>
<li><p>When you have done your work, put your report and code in the folder <code>lab_3</code> then commit them. Tag the commit named <code>&lt;&#x5B66;&#x53F7;/lab_3&gt;</code> which you want to submit. An example is <code>123456789/lab_3</code>. Finally your project will look like</p>
<pre><code>switchyard
  &#x251C;&#x2500;docs/
  &#x251C;&#x2500;.../
+ &#x251C;&#x2500;lab_3/
+ &#x2502; &#x251C;&#x2500;myrouter.py
  &#x2502; &#x251C;&#x2500;...
+ &#x2502; &#x2514;&#x2500;start_mininet.py
  &#x251C;&#x2500;.gitignore
  &#x2514;&#x2500;...
</code></pre><blockquote>
<p>[!WARNING]
The file names in your submission have to <strong>exactly</strong> match the file names above. Otherwise, you will lose points!</p>
</blockquote>
</li>
<li><p>Submit your work by pushing your local repository to your remote repository <strong>with your tags</strong> by running the command <code>git push origin --tags</code>.</p>
<blockquote>
<p>[!WARNING]
<strong>Only</strong> commit your source code and other necessary files to your local repository. If some generated files are not source code, ignore them by adding them in the file <code>.gitignore</code>.</p>
</blockquote>
</li>
</ol>

<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../ipv4-router.html" class="navigation navigation-prev " aria-label="Previous page: Lab 3-5: IPv4 Router">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="preparation.html" class="navigation navigation-next " aria-label="Next page: Task 1: Preparation">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Lab 3: Respond to ARP","level":"1.4.1","depth":2,"next":{"title":"Task 1: Preparation","level":"1.4.1.1","depth":3,"path":"content/ch03/subch01/preparation.md","ref":"content/ch03/subch01/preparation.md","articles":[]},"previous":{"title":"Lab 3-5: IPv4 Router","level":"1.4","depth":1,"path":"content/ch03/ipv4-router.md","ref":"content/ch03/ipv4-router.md","articles":[{"title":"Lab 3: Respond to ARP","level":"1.4.1","depth":2,"path":"content/ch03/subch01/lab-3.md","ref":"content/ch03/subch01/lab-3.md","articles":[{"title":"Task 1: Preparation","level":"1.4.1.1","depth":3,"path":"content/ch03/subch01/preparation.md","ref":"content/ch03/subch01/preparation.md","articles":[]},{"title":"Task 2: Handle ARP Request","level":"1.4.1.2","depth":3,"path":"content/ch03/subch01/handle-arp-request.md","ref":"content/ch03/subch01/handle-arp-request.md","articles":[]},{"title":"Task 3: Cached ARP Table","level":"1.4.1.3","depth":3,"path":"content/ch03/subch01/arp-table.md","ref":"content/ch03/subch01/arp-table.md","articles":[]}]},{"title":"FAQ","level":"1.4.2","depth":2,"path":"content/ch03/faq.md","ref":"content/ch03/faq.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["theme-comscore","back-to-top-button","-lunr","-search","search-pro","github","splitter","flexible-alerts","page-toc-button","auto-scroll-table","popup","anchors"],"pluginsConfig":{"styles":{"website":"styles/website.css"},"github":{"url":"https://github.com/shellqiqi/nju-network-experiments"},"splitter":{},"search-pro":{},"auto-scroll-table":{},"popup":{},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"page-toc-button":{},"back-to-top-button":{},"flexible-alerts":{"danger":{"className":"danger","icon":"fa fa-ban","label":"Attention"},"note":{"className":"info","icon":"fa fa-info-circle","label":"Note"},"style":"callout","tip":{"className":"tip","icon":"fa fa-lightbulb-o","label":"Tip"},"warning":{"className":"warning","icon":"fa fa-exclamation-triangle","label":"Warning"}},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"content/ch03/subch01/lab-3.md","mtime":"2020-03-24T13:21:14.092Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-03-24T13:21:20.286Z"},"basePath":"../../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../../gitbook/gitbook.js"></script>
    <script src="../../../gitbook/theme.js"></script>
    
        
        <script src="../../../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-auto-scroll-table/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

